const { Printer } = require('../models/printer');

async function initializeData() {
  try {
    // 检查是否已有打印机数据
    const printerCount = await Printer.count();
    
    if (printerCount === 0) {
      // 只在没有打印机数据时创建默认打印机
      const printers = [
        {
          name: '默认打印机',
          ip: '10.10.185.130',
          port: 631,
          protocol: 'IPP',
          enableColor: true,
          description: '默认IPP打印机',
          isOnline: true,
          taskCount: 0,
          lastOnline: new Date(),
          todayPrintCount: 0,
          failedPrintCount: 0
        }
      ];
      
      await Printer.bulkCreate(printers);
      console.log('初始数据创建成功');
    } else {
      console.log('已有打印机数据，跳过初始化');
    }
  } catch (error) {
    console.error('初始化数据失败:', error);
    throw error;
  }
}

module.exports = initializeData; 